package org.fqh.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.fqh.common.base.BaseServiceImpl;
import org.fqh.common.redis.RedisClientTemplate;
import org.fqh.system.dao.TSysUserDao;
import org.fqh.system.entity.TSysUser;
import org.fqh.system.service.TSysUserService;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

/**
* @author fqh 
* @version 创建时间：2017年11月29日 下午3:10:50
* 类说明
*/
@Service
public class TSysUserServiceImpl extends BaseServiceImpl<TSysUserDao,TSysUser> implements TSysUserService{
	

	 @Override
	public int insert(TSysUser entity) throws Exception  {
		String algorithmName = "md5";  
		String username = entity.getUsername();  
		String password = entity.getPassword();  
		entity.setRegisttime(new Date());
		String salt1 = username;  
		String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex();  
		int hashIterations = 2;   
		SimpleHash hash = new SimpleHash(algorithmName, password, salt1 + salt2, hashIterations);  
		entity.setSalt(salt2);
		String encodedPassword = hash.toHex();  
		entity.setPassword(encodedPassword);
		// entity.setLocked(0);
		return baseDao.insert(entity);
	}

	@Override
	public Set<String> findRoles(String username) throws Exception {
 
		return null;
	}

	@Override
	public Set<String> findPermissions(String username) throws Exception {
	 
		return null;
	}

	@Override
	public TSysUser findByUsername(String username) throws Exception  {
 
		return null;
	}
    
}
